package com.stockprediction.analysis;

import java.util.Set;

public class SentimentDictionary {
    private Set<String> positiveWords;
    private Set<String> negativeWords;

    public SentimentDictionary(Set<String> positiveWords, Set<String> negativeWords) {
        this.positiveWords = positiveWords;
        this.negativeWords = negativeWords;
    }

    // 计算文本的情感得分
    public double getSentimentScore(String text) {
        int posCount = 0, negCount = 0;
        String[] words = ChineseTokenizer.tokenize(text).split(" "); // 假设分词结果是用空格分割

        for (String word : words) {
            if (positiveWords.contains(word)) posCount++;
            if (negativeWords.contains(word)) negCount++;
        }

        return posCount - negCount;  // 正面词数 - 负面词数
    }
}
